package ACM_Brush;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class Solution094 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = null;
        root.right = new TreeNode(2);
        root.right.left = new TreeNode(3);
        root.right.right = null;
        List<Integer> result = new solution_094().inorderTraversal(root);
        result.forEach(i -> System.out.println(i));
    }
}

class solution_094 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        Deque<TreeNode> stack = new LinkedList<>();
        // 向左走到尽头
        while (root != null) {
            stack.push(root);
            root = root.left;
        }

        while (!stack.isEmpty()) {
            TreeNode top = stack.pop();
            result.add(top.val);
            top = top.right;
            while (top != null) {
                stack.push(top);
                top = top.left;
            }
        }
        return result;
    }
}